#pragma once

#include "EntityManager.h"
#include "FinanceManager.h"
#include "InputManager.h"
#include "OutputManager.h"
#include "BlueprintManager.h"

#include "Market/Comodities.h"

class BuildingManager
{
private:
	EntityManager entity_manager;
	FinanceManager finance_manager;
	InputManager input_manager;
	InputManager consumption_manager;
	OutputManager output_manager;

	static BlueprintManager bp_manager;

	uint32 max_buildings;
	uint32 curr_buildings;
	uint32 construction_limit;

public:
	BuildingManager();
	~BuildingManager();

	void Initialize(OpenVector<uint32>& comodities);

	void PlaceMarketOrders(BidData* buy_data, BidData* sell_data);
	void RunProduction();
	void ProcessMarketResults(const BidData* const buy_data, const BidData* const consumption_data, const BidData* const sell_data,
		const float* const mean, const float* const supply, const float* demand, const uint32 num_resources);
	void ProcessDefunctEntities(OpenMap<uint32, uint32>& removed_buyers, OpenMap<uint32, uint32>& removed_sellers);
	void AllocateNewProduction(const float* const comodity_mean, const uint32 output_hash,
		OpenMap<uint32, uint32>& new_buyers, OpenMap<uint32, uint32>& new_sellers);
	// AllocateNewConsumers?

	inline const uint32 GetAvailableSlots() { return (max_buildings - curr_buildings < construction_limit) ? max_buildings - curr_buildings : construction_limit; }
};